home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 June / PersonalComputerWorld-June2009-CoverdiscCD.iso / Software / Shareware / Mockups for Desktop 1.5.27 / MockupsForDesktop.air / MockupsAir.swf / scripts / MockupsBar.as < prev    next >
Encoding:
Text File  |  2009-03-03  |  7.8 KB  |  232 lines

  1. package
  2. {
  3.    import com.balsamiq.events.FileManagerEvent;
  4.    import com.balsamiq.file.FileDescriptor;
  5.    import com.plus9.mockups.Mockups;
  6.    import flash.events.ContextMenuEvent;
  7.    import flash.events.KeyboardEvent;
  8.    import flash.ui.ContextMenu;
  9.    import flash.ui.ContextMenuItem;
  10.    import flash.ui.Keyboard;
  11.    import mx.collections.ArrayCollection;
  12.    import mx.controls.TabBar;
  13.    import mx.core.UIComponent;
  14.    import mx.events.ItemClickEvent;
  15.    import mx.events.MenuEvent;
  16.    
  17.    public class MockupsBar extends UIComponent
  18.    {
  19.       protected var _nativeTabsWidth:Number;
  20.       
  21.       protected var _tabs:TabBar;
  22.       
  23.       protected var _rightClickLastPath:String;
  24.       
  25.       protected var _rightClickMenu:ContextMenu;
  26.       
  27.       protected var _mockups:Mockups;
  28.       
  29.       protected var _sm:StorageManagerAir;
  30.       
  31.       public function MockupsBar()
  32.       {
  33.          super();
  34.       }
  35.       
  36.       protected function onKeyDown(param1:KeyboardEvent) : void
  37.       {
  38.          var _loc2_:uint = 0;
  39.          var _loc3_:ItemClickEvent = null;
  40.          if(param1.ctrlKey && param1.charCode == Keyboard.TAB)
  41.          {
  42.             trace("CTRL+TAB");
  43.             _loc2_ = (_tabs.selectedIndex + 1) % _tabs.dataProvider.length;
  44.             _loc3_ = new ItemClickEvent(ItemClickEvent.ITEM_CLICK);
  45.             _loc3_.item = _tabs.dataProvider[_loc2_];
  46.             onTabsItemClick(_loc3_);
  47.          }
  48.       }
  49.       
  50.       protected function onSelectedFileChange(param1:FileManagerEvent = null) : void
  51.       {
  52.          var _loc3_:String = null;
  53.          var _loc4_:uint = 0;
  54.          var _loc5_:uint = 0;
  55.          var _loc2_:Array = _sm.getFileDescriptors();
  56.          if(_loc2_.length > 0)
  57.          {
  58.             _loc3_ = _sm.currentPath;
  59.             _loc4_ = _loc2_.length;
  60.             _loc5_ = 0;
  61.             while(_loc5_ < _loc4_)
  62.             {
  63.                if(FileDescriptor(_tabs.dataProvider[_loc5_]).path == _loc3_)
  64.                {
  65.                   _tabs.selectedIndex = _loc5_;
  66.                   break;
  67.                }
  68.                _loc5_++;
  69.             }
  70.          }
  71.       }
  72.       
  73.       protected function onRightClick(param1:ContextMenuEvent) : void
  74.       {
  75.          var _loc2_:uint = uint(_tabs.getChildIndex(param1.mouseTarget));
  76.          var _loc3_:FileDescriptor = FileDescriptor(_tabs.dataProvider[_loc2_]);
  77.          _rightClickLastPath = _loc3_.path;
  78.          _rightClickMenu.customItems = new Array();
  79.          var _loc4_:ContextMenuItem = new ContextMenuItem("Save Mockup",false,_loc3_.isDirty);
  80.          _loc4_.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,onRightClickMenuSelect);
  81.          _rightClickMenu.customItems.push(_loc4_);
  82.          _loc4_ = new ContextMenuItem("Close Mockup");
  83.          _loc4_.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,onRightClickMenuSelect);
  84.          _rightClickMenu.customItems.push(_loc4_);
  85.          _loc4_ = new ContextMenuItem("Clone As New Mockup",false,_loc2_ == _tabs.selectedIndex);
  86.          _loc4_.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,onRightClickMenuSelect);
  87.          _rightClickMenu.customItems.push(_loc4_);
  88.          _loc4_ = new ContextMenuItem("New Blank Mockup",true);
  89.          _loc4_.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,onRightClickMenuSelect);
  90.          _rightClickMenu.customItems.push(_loc4_);
  91.          _loc4_ = new ContextMenuItem("Save All Mockups");
  92.          _loc4_.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,onRightClickMenuSelect);
  93.          _rightClickMenu.customItems.push(_loc4_);
  94.       }
  95.       
  96.       public function get fileManager() : StorageManagerAir
  97.       {
  98.          return _sm;
  99.       }
  100.       
  101.       override protected function createChildren() : void
  102.       {
  103.          _tabs = new TabBar();
  104.          _tabs.addEventListener(ItemClickEvent.ITEM_CLICK,onTabsItemClick);
  105.          _rightClickMenu = new ContextMenu();
  106.          _rightClickMenu.hideBuiltInItems();
  107.          _rightClickMenu.addEventListener(ContextMenuEvent.MENU_SELECT,onRightClick);
  108.          _tabs.contextMenu = _rightClickMenu;
  109.          _tabs.labelFunction = formatLabel;
  110.          if(_sm)
  111.          {
  112.             updateTabs();
  113.             onSelectedFileChange();
  114.          }
  115.          _tabs.styleName = "mockupsBar";
  116.          addChild(_tabs);
  117.          super.createChildren();
  118.       }
  119.       
  120.       public function set mockups(param1:Mockups) : void
  121.       {
  122.          _mockups = param1;
  123.          stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
  124.       }
  125.       
  126.       public function set fileManager(param1:StorageManagerAir) : void
  127.       {
  128.          _sm = param1;
  129.          _sm.addEventListener(FileManagerEvent.FILE_LIST_CHANGE,updateTabs);
  130.          _sm.addEventListener(FileManagerEvent.SELECTED_FILE_CHANGE,onSelectedFileChange);
  131.          updateTabs();
  132.          onSelectedFileChange();
  133.       }
  134.       
  135.       override protected function measure() : void
  136.       {
  137.          super.measure();
  138.          measuredWidth = _tabs.measuredWidth;
  139.          measuredHeight = measuredMinHeight = _tabs.measuredMinHeight;
  140.       }
  141.       
  142.       protected function updateTabs(param1:FileManagerEvent = null) : void
  143.       {
  144.          _tabs.dataProvider = _sm.getFileDescriptors();
  145.          onSelectedFileChange();
  146.          _tabs.setStyle("tabWidth",undefined);
  147.          _tabs.validateNow();
  148.          _nativeTabsWidth = _tabs.measuredWidth + 30;
  149.          invalidateDisplayList();
  150.       }
  151.       
  152.       protected function onNewButtonItemClick(param1:MenuEvent) : void
  153.       {
  154.          var _loc2_:String = null;
  155.          switch(String(XML(param1.item).@kind))
  156.          {
  157.             case "blank":
  158.                _sm.createNewFile();
  159.                break;
  160.             case "clone":
  161.                _sm.createCloneOfCurrentMockup();
  162.                break;
  163.             case "copy":
  164.                _loc2_ = String(XML(param1.item).@path);
  165.                _sm.createNewFile(_sm.getFileDescriptor(_loc2_).data);
  166.          }
  167.       }
  168.       
  169.       protected function onRightClickMenuSelect(param1:ContextMenuEvent) : void
  170.       {
  171.          var _loc2_:String = ContextMenuItem(param1.target).caption;
  172.          switch(_loc2_)
  173.          {
  174.             case "Save Mockup":
  175.                _sm.savePath(_rightClickLastPath);
  176.                break;
  177.             case "Close Mockup":
  178.                _sm.closeFileWithPrompt(_rightClickLastPath);
  179.                break;
  180.             case "Clone As New Mockup":
  181.                _sm.createCloneOfCurrentMockup();
  182.                break;
  183.             case "New Blank Mockup":
  184.                _sm.newMockup();
  185.                break;
  186.             case "Save All Mockups":
  187.                _sm.saveAllFilesToDisk();
  188.          }
  189.       }
  190.       
  191.       public function get mockups() : Mockups
  192.       {
  193.          return _mockups;
  194.       }
  195.       
  196.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  197.       {
  198.          super.updateDisplayList(param1,param2);
  199.          if(!_tabs.dataProvider)
  200.          {
  201.             return;
  202.          }
  203.          if(param1 == 0)
  204.          {
  205.             return;
  206.          }
  207.          if(_nativeTabsWidth > param1)
  208.          {
  209.             _tabs.setActualSize(param1,24);
  210.             _tabs.setStyle("tabWidth",param1 / (_tabs.dataProvider as ArrayCollection).length);
  211.          }
  212.          else
  213.          {
  214.             _tabs.setActualSize(_nativeTabsWidth,24);
  215.             _tabs.setStyle("tabWidth",undefined);
  216.          }
  217.       }
  218.       
  219.       protected function onTabsItemClick(param1:ItemClickEvent) : void
  220.       {
  221.          var _loc2_:FileDescriptor = FileDescriptor(param1.item);
  222.          _sm.selectFile(_loc2_.path);
  223.       }
  224.       
  225.       protected function formatLabel(param1:FileDescriptor) : String
  226.       {
  227.          return (param1.isDirty ? "* " : "") + (param1.name == "" ? "New Mockup" : param1.name);
  228.       }
  229.    }
  230. }
  231.  
  232.